load("@rules_cc//cc:cc_binary.bzl", "cc_binary")
load("@rules_cc//cc:cc_library.bzl", "cc_library")

cc_library(
    name = "nanobind",
    srcs = [
        "include/nanobind/stl/detail/nb_dict.h",
        "include/nanobind/stl/detail/nb_list.h",
        "include/nanobind/stl/detail/traits.h",
        "src/buffer.h",
        "src/common.cpp",
        "src/error.cpp",
        "src/hash.h",
        "src/implicit.cpp",
        "src/nb_abi.h",
        "src/nb_enum.cpp",
        "src/nb_ft.cpp",
        "src/nb_ft.h",
        "src/nb_func.cpp",
        "src/nb_internals.cpp",
        "src/nb_internals.h",
        "src/nb_ndarray.cpp",
        "src/nb_static_property.cpp",
        "src/nb_type.cpp",
        "src/trampoline.cpp",
    ],
    hdrs = glob(
        include = [
            "include/nanobind/*.h",
            "include/nanobind/stl/*.h",
            "include/nanobind/stl/detail/*.h",
        ],
        allow_empty = False,
    ),
    additional_linker_inputs = select({
        "@platforms//os:macos": [":cmake/darwin-ld-cpython.sym"],
        "//conditions:default": [],
    }),
    copts = select({
        "@rules_cc//cc/compiler:msvc-cl": ["/std:c++17"],
        "//conditions:default": [
            "--std=c++17",
            "-fexceptions",
            "-frtti",
        ],
    }),
    includes = ["include"],
    linkopts = select({
        "@platforms//os:macos": [
            "-Wl,@$(location :cmake/darwin-ld-cpython.sym)",
        ],
        "//conditions:default": [],
    }),
    strip_include_prefix = "include",
    visibility = ["//visibility:public"],
    deps = [
        "@robin-map//:robin-map",
        "@rules_python//python/cc:current_py_cc_headers",
    ],
)

cc_library(
    name = "nanobind_eigen",
    hdrs = glob([
        "include/nanobind/eigen/*.h",
    ]),
    features = ["parse_headers"],
    visibility = ["//visibility:public"],
    deps = [
        ":nanobind",
        "@eigen",
    ],
)

cc_binary(
    name = "linktest",
    linkopts = select({
        "@platforms//os:macos": ["-all_load"],
        "//conditions:default": [],
    }),
    linkshared = True,
    visibility = ["//visibility:private"],
    deps = [":nanobind"],
)
